package com.whiteseason.whitebot.util.OSU;

import com.whiteseason.whitebot.pojo.UserInfo;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Component;
import org.springframework.web.client.RestClientException;
import org.springframework.web.client.RestTemplate;

import java.util.HashMap;
import java.util.Map;


@Component
@Slf4j
public class UserGet {
    private String get_user;
    private String key;
    @Autowired
    private RestTemplate restTemplate;

    @Value("${osu.getuser}")
    public void setGet_user(String get_user) {
        this.get_user = get_user;
    }
    @Value("${osu.key}")
    public void setKey(String key) {
        this.key = key;
    }

    public UserInfo getUser(String name, int mode) throws RestClientException {
        String url = get_user + "k=" +key + "&u=" + name + "&m=" + mode;
        System.out.println(url);
        UserInfo[] users = restTemplate.getForObject(url,UserInfo[].class);
        if(users!= null)
            return users[0];
        else
            return null;
    }
}
